<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Insert title here</title>
	<script type="text/javascript">
	
		// json对象1
		function f01() {
			var obj = {
					"name" : "warrior",
					"age" : 24,
					"gender" : "F"
			};
			// alert(obj.name);
			alert(obj["name"]);
		}
		
		// json对象2
		function f02() {
			var obj = {
					"name" : "庠序科技",
					"address" : {
						"city" : "重庆",
						"street" : "沙坪坝三峡广场"
					}
			};
			// alert(obj.address.street);
			alert(obj["address"]["street"]);
		}
		
		// json数组
		function f03() {
			var arr = [
			           {"name" : "WYM", "age" : 27},
			           {"name" : "WYC", "age" : 25},
			           {"name" : "WYS", "age" : 24}
			           ];
			// alert(arr[2].name);
			alert(arr[1]["name"]);
		}
		
		// 将json字符串转换成json对象（注意：js对象包含json对象） 
		function f04() {
			var str = '{"name" : "warrior","age" : 24,"gender" : "F" }';
			var obj = JSON.parse(str);
			alert(obj.name);
		}
		
		// 将json数组转换成json数组（注意：js数组包含json数组）
		function f05() {
			var str = '[{"name":"warrior","age":24},' + 
					     '{"name":"fury","age":18}]';
			// 注意：返回的是由js对象组成的数组
			var arr = JSON.parse(str);
			
			alert(arr[1].name);
		}
		
	</script>
</head>
<body>
	<a href="javascript:f01();">ClickMe01</a>
	<br />
	<a href="javascript:f02();">ClickMe02</a>
	<br />
	<a href="javascript:f03();">ClickMe03</a>
	<br />
	<a href="javascript:f04();">ClickMe04</a>
	<br />
	<a href="javascript:f05();">ClickMe05</a>
</body>
</html>